package org.dfl.plugin.editor.commands;

import javax.swing.JOptionPane;

import org.dfl.plugin.editor.model.DflDiagram;
import org.dfl.core.model.analysis.ReverseDiagram;
import org.eclipse.gef.commands.Command;
import org.dfl.messages.Messages;

public class CheckHierarchicalCommand extends Command {
	DflDiagram diagram;
	
	public CheckHierarchicalCommand(DflDiagram diagram) {
		super();
		this.diagram = diagram;
	}

	@Override
	public boolean canExecute() {
		return (diagram!=null && diagram.isEditable());
	}

	@Override
	public void execute() {
		// check connections
		if (!diagram.allTranisitonsWellDefined()) {
			JOptionPane.showMessageDialog(null, Messages.CheckHierarchicalCommand_errorNotWellDefined);
			return;
		}
		
		ReverseDiagram rd = new ReverseDiagram(diagram);
		if (rd.isHierarchical()) {
			JOptionPane.showMessageDialog(null, Messages.CheckHierarchicalCommand_infoIsHierachical);
		} else {
			JOptionPane.showMessageDialog(null, Messages.CheckHierarchicalCommand_infoIsNotHierarchical);
		}
	}

	@Override
	public boolean canUndo() {
		return false;
	}
}
